/*
* 菜单结构
* */

var Menu = {
	reports: [
		{
			name: '办公',
			child: [
				{
					name: '待办事项',
					url: 'views/index/waitTask/waitTask.html',
					icon: '&#xe609;',
					class: 'bg-1'
				},
				{
					name: '已办事项',
					url: 'views/index/histTask/histTask.html',
					icon: '&#xe612;',
					class: 'bg-2'
				},
				{
					name: '我的流程',
					url: 'views/index/selfOrder/selfOrder.html',
					icon: '&#xe606;',
					class: 'bg-3'
				}
			]
		},
		{
			name: '报表',
			child: [
				{
					name: '账户余额表',
					url: 'views/reports/accountBalance/accountBalance.html',
					icon: '&#xe600;',
					class: 'bg-2'
				},
				{
					name: '库存表',
					url: 'views/reports/stock/stock.html',
					icon: '&#xe601;',
					class: 'bg-4'
				},
				{
					name: '往来报表',
					url: 'views/reports/dealings/dealings.html',
					icon: '&#xe617;',
					class: 'bg-1'
				},
				{
					name: '收付损益表',
					url: 'views/reports/paymentLossProfit/paymentLossProfit.html',
					icon: '&#xe602;',
					class: 'bg-4'
				},
				{
					name: '损益表',
					url: 'views/reports/lossProfit/lossProfit.html',
					icon: '&#xe61d;',
					class: 'bg-5'
				},
				{
					name: '现金流量表',
					url: 'views/reports/cashFlow/cashFlow.html',
					icon: '&#xe603;',
					class: 'bg-3'
				},{
					name: '资产负债表',
					url: 'views/reports/balanceSheet/balanceSheet.html',
					icon: '&#xe667;',
					class: 'bg-1'
				},
				// {
				// 	name: '仓库资源余额表',
				// 	url: 'views/reports/resourceBalance/resourceBalance.html',
				// 	icon: '&#xe817;',
				// 	class: 'bg-2'
				// }
			]
		},
	],
	inOut: [
		{
		name: '进出单类型',
		url: 'views/inout/type/type.html',
		icon: '&#xe6f9;',
		class: 'bg-1'
		},{
			name: '进出单创建',
			url: 'views/inout/new/new.html',
			icon: '&#xe605;',
			class: 'bg-2'
		},{
			name: '进出单列表',
			url: 'views/inout/list/list.html',
			icon: '&#xe66f;',
			class: 'bg-3'
		}
	],
	approve: [
		{
			name: '结算单新增',
			url: 'views/approves/new/new.html',
			icon: '&#xe605;',
			class: 'bg-4'
		},{
			name: '结算单审核',
			url: 'views/approves/list/list.html',
			icon: '&#xe795;',
			class: 'bg-5'
		}
	]

};

$(function(){
	var params = Utils.getQueryString('accessid');
	 // console.log(params)
	if(params){
		//保存用户登陆信息
		window.localStorage['accessid'] = params;
	}

	document.getElementById('reports').innerHTML = template('typeTem', Menu.reports);
	// document.getElementById('main').innerHTML = template('typeTem', Menu.main);
// document.getElementById('inOut').innerHTML = template('reportTem', Menu.inOut);
// document.getElementById('approve').innerHTML = template('reportTem', Menu.approve);

	//获取待办次数提醒
// Utils.request(Utils.Api.waitTaskCount, {}, function(res){
// 	$('#waitCount').html(res.results)
// })

	Utils.request(Utils.Api.moduleGet, {}, function(res){
		var html = '';
		const style = ['tips-warning', 'tips-success', 'tips-info','tips-warning']
		const icon = ['x-icon-warning', 'x-icon-success', 'x-icon-important', 'x-icon-warning']
		res.rows.forEach(function(item, index){
			html += '<div class="tips tips-large ' + style[index] +'">' +
				'<span class="x-icon ' + icon[index] + '"><i class="mui-icon mui-icon-star-filled"></i></span>' +
				'<div class="tips-content">' +
				'<h2>' + item.moduleName +'</h2>' +
				'<div id="' + item.moduleId + '" class="cms-content" style="min-height:100px;"><p>该模块暂无内容</p></div>\n' +
				'</div>' +
				'</div>'

			Utils.request(Utils.Api.moduleContentGet, {
				moduleId: item.moduleId
			}, function(res){
				var data = ''
				res.rows.forEach(function(n){
					data += '<li style="padding-right: 20px"><a href="http://www.daydaycs.com/system/Cms/contentDetail?contentId='+ n.contentId +'">' + n.title + '<span class="fr">' + n.modifyTimeString +'</span></a></li>'
				})
				if(data!== ''){
					$('#'+ item.moduleId).html(data)
				}
			})

		})
		document.getElementById('main').innerHTML = html
	})

	//获取用户信息
	Utils.request(Utils.Api.userInfo, {} ,function(res){
		$('#createName').html(res.data.psnId);
		$('#psnName').html(res.data.psnName);
	})

	//退出登陆
	$('#logoutBtn').click(function () {
		Utils.request(Utils.Api.loginOut, {}, function(res){
			window.localStorage.clear();
			window.open(res.data.redirect_url)
		})
	})


});


//跳转个人资料
function openUserDetail(){
	mui.openWindow({
		url: 'views/user/personal/personal.html',
	})
}